package com.dlnu.shoping.shopping.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dlnu.shoping.shopping.common.Result;
import com.dlnu.shoping.shopping.mapper.ProductInformationDao;
import com.dlnu.shoping.shopping.service.IProductService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class IProductServiceImpl implements IProductService {
    @Resource
    private ProductInformationDao productDao;

    @Override
    public Result searchByProId(Integer proId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("pro_id",proId);
        return new Result(productDao.selectOne(wrapper));
    }

    //    通过名字查询商品
    @Override
    public Result searchByName(String name) {
        QueryWrapper wrapper = new QueryWrapper();
        if(StringUtils.isNotEmpty(name)) {
            wrapper.like("name",name);
        }
        wrapper.orderByDesc("pro_id");
        return new Result(productDao.selectList(wrapper));
    }

//    通过商品类别查询商品名字
    @Override
    public Result queryByCategoryId(Integer pageNo, Integer pageSize, Integer categoryId) {
        Page page = new Page(pageNo,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("category_id",categoryId);
        wrapper.orderByDesc("pro_id");
        return new Result(productDao.selectPage(page,wrapper));
    }


}
